/**
 * @file   1121.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Mon May 17 20:39:04 2021
 * 
 * @brief  PAT 1121
 * 
 * 
 */
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    int pairs;
    cin>>pairs;
    map<string,string> couple;
    for(int i=0;i<pairs;i++){
	string s1,s2;
	cin>>s1>>s2;
	couple[s1]=s2;
	couple[s2]=s1;
    }
    set<string> singledog;
    map<string,bool> inparty;
    int checknum;
    cin>>checknum;
    for(int i=0;i<checknum;i++){
	string s;
	cin>>s;
	inparty[s]=true;
    }
    for(auto it=inparty.begin();it!=inparty.end();it++){
	if(couple.count(it->first)==0){
	    singledog.insert(it->first);
	}else if(inparty[couple[it->first]]==false){
	    singledog.insert(it->first);
	}
    }
    cout<<singledog.size()<<endl;
    for(auto it=singledog.begin();it!=singledog.end();it++){
	if(it==singledog.begin()){
	    cout<<*it;
	}else{
	    cout<<" "<<*it;
	}
    }
    if(singledog.size()){
    cout<<endl;
    }
}
